﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Yipusoft.Duty.Model;

public partial class BasicBase_Duty_AddUser : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
            Bind();

    }
    private void Bind()
    {
        string DepartmentID = Yipusoft.Account.BLL.User.GetUser(User.Identity.Name).DepartmentID;
        if (string.IsNullOrEmpty(DepartmentID))
            return;

        string Where = string.Empty;
        if (DepartmentID.Substring(4, 1).Equals("0"))
        {
            Where = "Left(DepartmentID,5)='" + DepartmentID.Substring(0, 5) + "'";           

        }
        else
        {
            Where = "DepartmentID='" + DepartmentID + "'";
        }

        this.DptDepartment.DataSource= Yipusoft.Account.BLL.Department.GetList(Where);
        this.DptDepartment.DataTextField = "FullName";
        this.DptDepartment.DataValueField = "DepartmentID";
        this.DptDepartment.DataBind();

        
    }
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        lblpromt.Text = "";
        MemberUserInfo model = Yipusoft.Duty.BLL.MemberUser.GetModel(txtUserID.Text.Trim());
        if (model != null)
        {
            lblpromt.Text = "此用户ID已存在,请更换用户ID";
            model = null;
            return;
        }


        string UserID = this.txtUserID.Text;
        string UserName = this.txtUserName.Text;
        string DepartmentID = DptDepartment.SelectedValue;
        string SetID = Yipusoft.Account.BLL.User.GetUser(User.Identity.Name).UserID;
        DateTime SetDate = DateTime.Now;

         model = new MemberUserInfo();
        model.UserID = UserID;
        model.UserName = UserName;
        model.DepartmentID = DepartmentID;
        model.SetID = SetID;
        model.SetDate = SetDate;
        if (Yipusoft.Duty.BLL.MemberUser.Add(model) > 0)
            lblpromt.Text = "添加成功";

    }
}
